﻿using System;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Bogus;
using IceZero.Business;
using IceZero.Business.Models.Results;
using IceZero.DataStore;
using IceZero.DataStore.InitDB;
using IceZero.DataStore.Models;
using IceZero.RootNode;
using IceZero.RootNode.Helpers;

namespace IcsZero.Client.Cmd
{
    class Program
    {
        static void Main(string[] args)
        {
            var options = new JsonSerializerOptions() { WriteIndented = true };

            //Nhibernate 配置
            NHibernateHelperConfig.ConfigAddInputStream(NHibernateHelper.Configuration, NHibernateHelper.GenMappingXMLs(genFile: true));
            //NHibernateHelper.Configure("home.mysql.hibernate.cfg.xml");
            //NHibernateHelper.Configure("work.mysql.hibernate.cfg.xml");
            NHibernateHelper.Configure("work.mssql.hibernate.cfg.xml");
            //NHibernateHelper.Configure("sqlite3.hibernate.cfg.xml");
            //NHibernateHelper.AutoBuildUpdateTable(rebuild: false);
            //NHibernateHelper.BindCurrentSessionContext();
            //new UserDomainDBInitializer().Initialize();
            //new DbInitializer().Initialize();

            //配置 Mapper映射
            AutoMapperHelper.Configure();
            var ds = IceZeroNode.Default.BusinessNode.CatBusiness.CatDataStore;
            Randomizer.Seed = new Random(66457);
            for (int i = 10001; i < 50000; i++)
            {
                var cat = new Faker<Cat>()
                    .RuleFor(o => o.Name, f => f.Name.FirstName())
                    .RuleFor(o => o.Weight, f => f.Random.Float(2.1F, 5.5F))
                    .RuleFor(o => o.Id, f => "Cat" + i)
                    .RuleFor(o => o.Sex, f => f.Random.Int(1000) % 2 == 0 ? "male" : "female")
                    .RuleFor(o => o.Code, f => f.Random.Int(1000))
                    .Generate();
                ds.Save(cat);
                Console.WriteLine(i);
            }
            Console.WriteLine("程序执行完毕");
        }
    }
}
